import { AbsSvgUnitParser } from "../absunitparser"
import DevGraphInfo from "../../../../../canvas/common/struct/basestruct/devgraphinfo";
class UseParser extends AbsSvgUnitParser{
    constructor(){
        super();
    }
    parse(mainEle){
        let unitInfo = new DevGraphInfo.DevGraphInfo();
        unitInfo.type = 0x0202;
        let transformStr = '';
        const attributes = mainEle.attributes;
        for (let i = 0; i < attributes.length; i++) {
            const attr = attributes[i];
            if (attr.name == 'x') {
                unitInfo.x = parseFloat(attr.value);
            }
            else if (attr.name == 'y') {
                unitInfo.y = parseFloat(attr.value);
            }
            else if (attr.name == 'xlink:href') {
                unitInfo.sSymbolName = attr.value.replace('#','');
            }
            else if (attr.name == 'transform'){
                transformStr = attr.value;
            }
        }
        
        let point = {x:unitInfo.x,y:unitInfo.y};
        if (transformStr.length > 1){
            let transRet = this.transform2SystemCoord(point,transformStr);
            let transPt = transRet.pt;
            this.chg2SysCoord(transPt);
            unitInfo.x = transPt.x;
            unitInfo.y = transPt.y;

            unitInfo.scalex = Math.abs(transRet.scale.sx);
            unitInfo.scaley = Math.abs(transRet.scale.sy);
            unitInfo.angle = transRet.rot.angle;
        }
        unitInfo.pos.x = unitInfo.x;
        unitInfo.pos.y = unitInfo.y;
        
        return unitInfo;
    }
}

export {UseParser}